package com.wgt.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wgt on 2017/6/14.
 */
public class Subject {


    //用来存储所有的观察者
    private List<Observer> observers =new ArrayList<>();
    //标识：状态
    private int status;


    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
        notifyAllObserver();
    }

    /**
     * 注册观察者
     * @param observer
     */
    public void attach(Observer observer){
        System.out.println(observer);
        observers.add(observer);
    }

    public void notifyAllObserver(){
        for (Observer observer:observers){
            observer.update();
        }
    }
}
